#include<stdio.h>

struct list {
    struct list* next;
    int data;
};

struct list* revert_list(struct list* head, int n)
{
    if(head == NULL) {
        return NULL;
    }
    struct list* p = head;
    struct list* q = head->next;
    struct list* k = head;

    while(q && n--) {
        p->next = q->next;
        q->next = k;
        k = q;
        q = p->next;
    }
    return k;
}

#define TEST_NUM 10
void main() {
    int test_num = TEST_NUM;
    struct list* head = (struct list *)malloc(sizeof(struct list));
    head->data = -1;
    head->next = NULL;
    struct list* cur = head;
    while(test_num--) {
        struct list* node = (struct list *)malloc(sizeof(struct list));
        node->data = test_num;
        node->next = NULL;
        cur->next = node;
        cur = node;
    }

    head->next = revert_list(head->next, 5);

    cur = head->next;
    while(cur)
    {
        struct list *p = cur;
        printf("%d\t", cur->data);
        cur = cur->next;
        free(p);
    }
}
